const Queue = require('../queue/queue');

module.exports = class LoopQueue extends Queue {
  constructor(item) {
    super(item);
  }

  getIndex(index) {
    const { length } = this.items;
    return index > length ? index % length : index;
  }

  find(index) {
    return !this.isEmpty ? this.items[this.getIndex(index)] : null;
  }
};
